package cn.tedu.tickets;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestWindow {
         public static void main(String[] args) {
        Window window = new Window();
        /*new Thread(window).start();
        new Thread(window).start();
        new Thread(window).start();*/
        /*线程池方法 ExecutorService
        * nextFixedThreadPool(线程数)*/
        /*使用线程池 存放指定线程数5*/
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        for (int i = 1; i <= 100; i++) {
            executorService.execute(window);
        }
        executorService.shutdown();//关闭线程池

    }
}

class Window implements Runnable {
    int a = 100, b = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (Window.class) {
                if (a >= 1) {
                    System.out.println(Thread.currentThread().getName() + "\t" + a--);
                    ++b;
                }
                if (a <= 0) {
                    break;
                }
            }
        }
      //  System.out.println("共卖出" + b + "张票");
    }
}
